$(function () {
    var permission_datagird = $("#permission_datagird");

    permission_datagird.datagrid({
        url:"/permission/list",
        fit:true,
        fitColumns:true,
        pagination:true,
        border:false,
        singleSelect:true,
        striped:true,//行号 斑马线
        columns:
            [[
                {field:'name',title:'权限名称',width:100},
                {field:'resource',title:'权限表达式',width:100}
            ]],
        toolbar:"#permission_datagrid_toolbar"
    });

    var cmdObj = {
        reload : function () {
            $.messager.confirm("提示","您确定要加载权限吗?",function (yes) {
                if(yes){
                    $.post("/permission/reload",{},function (data) {
                        if(data.success){
                            $.messager.alert("提示","加载成功","info",function () {
                                permission_datagird.datagrid("reload");
                            });
                        }
                    })
                }
            })
        }
    };
    
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        cmdObj[cmd]();
    })
});
